from rest_framework import serializers
# from user.loginserializer import LoginSerializer
# from user.register_serializers import RegisterSerializer
from user.models import User
from .models import Channel, Article
from question.models import Label


class RegisterSerializer(serializers.ModelSerializer):
    sms_code = serializers.IntegerField(write_only=True)
    username = serializers.CharField()
    password = serializers.CharField(write_only=True)
    mobile = serializers.CharField()

    class Meta:
        model = User
        fields = ['username', 'password', 'sms_code', 'mobile','avatar']



class ArticleSerializerForCreate(serializers.ModelSerializer):
    image = serializers.CharField(required=False, default='',allow_blank=True)

    class Meta:
        model = Article
        exclude = ('collected_users',)

#频道列表序列化器
class ChannelSerializer(serializers.ModelSerializer):
    class Meta:
        model = Channel
        fields = [
            'id',
            'name'
        ]

class ArticleSerializer(serializers.ModelSerializer):
    user = RegisterSerializer(read_only=True)
    collected= serializers.BooleanField(default=False)
    class Meta:
        model = Article
        fields = [
            'id',
            'user',
            'collected',
            'content',
            'labels',
            'title',
            'title',
            'channel',
            'image',]


class LabelSerializer(serializers.Serializer):
    id =serializers.IntegerField(read_only=True)
    label_name = serializers.StringRelatedField()

class ArticleSerializerList(serializers.ModelSerializer):
    user =serializers.CharField(read_only=True)

    class Meta:
        model =Article
        fields = '__all__'
